module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	var ApiHeader = /*@__PURE__*/ (function(Component) {
		function ApiHeader(props) {
			Component.call(this, props);
			this.data = {
				msg: "你的积分已达到1000分！恭喜你可以兑换VIP会员"
			};
		}

		if (Component) ApiHeader.__proto__ = Component;
		ApiHeader.prototype = Object.create(Component && Component.prototype);
		ApiHeader.prototype.constructor = ApiHeader;
		ApiHeader.prototype.apiready = function() {};
		ApiHeader.prototype.getMsg = function() {
			console.log(api);
			// 发送消息给到父组件，发送的消息名称是toParent
			this.fire("toParent", {msg: this.data.msg});
		};
		ApiHeader.prototype.apiFn = function() {
			api.removeEventListener({
				name: "sendParent"
			});

			api.sendEvent({
				name: "sendParent",
				extra: {
					usernmae: "老陈",
					type: "帅哥！"
				}
			});
		};
		ApiHeader.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "page"},
				apivm.h("view", null, "头部组件"),
				apivm.h("view", null, this.props.title),
				apivm.h("view", null, this.props.user.name),

				apivm.h(
					"view",
					{
						onclick: function(event) {
							if (this$1.getMsg) {
								this$1.getMsg(event);
							} else {
								getMsg(event);
							}
						}
					},
					"消息"
				),
				apivm.h(
					"view",
					{
						onclick: function(event) {
							if (this$1.apiFn) {
								this$1.apiFn(event);
							} else {
								apiFn(event);
							}
						}
					},
					"api事件触发"
				)
			);
		};

		return ApiHeader;
	})(Component);
	apivm.define("api-header", ApiHeader);

	var Tpl = /*@__PURE__*/ (function(Component) {
		function Tpl(props) {
			Component.call(this, props);
			this.data = {
				text: 123456789,
				user: {
					name: "老陈",
					age: 18
				},

				childMsg: ""
			};
		}

		if (Component) Tpl.__proto__ = Component;
		Tpl.prototype = Object.create(Component && Component.prototype);
		Tpl.prototype.constructor = Tpl;
		Tpl.prototype.apiready = function() {
			api.addEventListener({name: "sendParent"}, function(ret) {
				console.log(ret);
			});
		};
		Tpl.prototype.showMsg = function(event) {
			console.log(event);
			this.data.childMsg = event.detail.msg;
		};
		Tpl.prototype.loginFn = function() {
			api.toast({
				msg: "登录成功",
				duration: 20000,
				location: "top"
			});
		};
		Tpl.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "page"},
				apivm.h("api-header", {
					title: this.data.text,
					user: this.data.user,
					ontoParent: function(event) {
						if (this$1.showMsg) {
							this$1.showMsg(event);
						} else {
							showMsg(event);
						}
					}
				}),

				apivm.h("view", null, "子组件消息"),
				apivm.h("view", null, this.data.childMsg),

				apivm.h(
					"button",
					{
						onclick: function(event) {
							if (this$1.loginFn) {
								this$1.loginFn(event);
							} else {
								loginFn(event);
							}
						}
					},
					"登录"
				)
			);
		};

		return Tpl;
	})(Component);
	apivm.define("tpl", Tpl);
	apivm.render(apivm.h("tpl", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}